package com.example.adminvue.controller;

import com.example.adminvue.domain.AjaxResult;
import com.example.adminvue.domain.BKind;
import com.example.adminvue.service.BKindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/web/kind")
public class BKindController  extends BaseController
{
    @Autowired
    private BKindService bKindService;

    @GetMapping("/list")
    public AjaxResult list(BKind kind)
    {
        List<BKind> list = bKindService.selectList(kind);
        return AjaxResult.success(list);
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return AjaxResult.success(bKindService.selectById(id));
    }

    @PostMapping
    public AjaxResult add(@Validated @RequestBody BKind kind)
    {
        return toAjax(bKindService.insert(kind));
    }

    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BKind kind)
    {
        return toAjax(bKindService.update(kind));
    }

    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id)
    {
        return toAjax(bKindService.deleteById(id));
    }

}
